{
    "cells": [
        {
            "attachments": {},
            "cell_type": "markdown",
            "id": "f3ca56f0-6ef1-426f-bac5-fd7c374d0f51",
            "metadata": {},
            "source": [
                "# Chroma Demo"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "778ee662",
            "metadata": {},
            "outputs": [],
            "source": [
                "import logging\n",
                "import sys\n",
                "\n",
                "logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
                "logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "262f990a-79c8-413a-9f3c-cd9a3c191307",
            "metadata": {},
            "outputs": [],
            "source": [
                "from gpt_index.readers.chroma import ChromaReader"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "252f8163-7297-44b6-a838-709e9662f3d6",
            "metadata": {},
            "outputs": [],
            "source": [
                "# The chroma reader loads data from a persisted Chroma collection.\n",
                "# This requires a collection name and a persist directory.\n",
                "\n",
                "reader = ChromaReader(\n",
                "    collection_name=\"chroma_collection\",\n",
                "    persist_directory=\"examples/data_connectors/chroma_collection\"\n",
                ")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "53b49187-8477-436c-9718-5d2f8cc6fad0",
            "metadata": {},
            "outputs": [],
            "source": [
                "# the query_vector is an embedding representation of your query.\n",
                "# Example query vector:\n",
                "#   query_vector=[0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3]\n",
                "\n",
                "query_vector=[n1, n2, n3, ...]"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "a88be1c4-603f-48b9-ac64-10a219af4951",
            "metadata": {},
            "outputs": [],
            "source": [
                "# NOTE: Required args are collection_name, query_vector.\n",
                "# See the Python client: https://github.com/qdrant/qdrant_client\n",
                "# for more details. \n",
                "documents = reader.load_data(collection_name=\"demo\", query_vector=query_vector, limit=5)"
            ]
        },
        {
            "cell_type": "markdown",
            "id": "169b4273-eb20-4d06-9ffe-71320f4570f6",
            "metadata": {},
            "source": [
                "### Create index"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "ac4563a1",
            "metadata": {},
            "outputs": [],
            "source": [
                "from gpt_index.indices import GPTListIndex\n",
                "index = GPTListIndex.from_documents(documents)"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "f06b02db",
            "metadata": {},
            "outputs": [],
            "source": [
                "# set Logging to DEBUG for more detailed outputs\n",
                "response = index.query(\"<query_text>\")"
            ]
        },
        {
            "cell_type": "code",
            "execution_count": null,
            "id": "97d1ae80",
            "metadata": {},
            "outputs": [],
            "source": [
                "display(Markdown(f\"<b>{response}</b>\"))"
            ]
        }
    ],
    "metadata": {
        "kernelspec": {
            "display_name": "chroma-gpt-index",
            "language": "python",
            "name": "python3"
        },
        "language_info": {
            "codemirror_mode": {
                "name": "ipython",
                "version": 3
            },
            "file_extension": ".py",
            "mimetype": "text/x-python",
            "name": "python",
            "nbconvert_exporter": "python",
            "pygments_lexer": "ipython3",
            "version": "3.9.16"
        },
        "vscode": {
            "interpreter": {
                "hash": "0ac390d292208ca2380c85f5bce7ded36a7a25670a97c40b8009630eb36cb06e"
            }
        }
    },
    "nbformat": 4,
    "nbformat_minor": 5
}